package com.zy.springcloud.cloudconsumeruser.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.zy.springcloud.cloudconsumeruser.bean.User;
import com.zy.springcloud.cloudconsumeruser.service.MovieServiceFeign;
import com.zy.springcloud.cloudconsumeruser.service.UserService;
import com.zy.springcloud.movie.bean.Movie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: zy 690748807@qq.com
 * @Description: TODO
 * @Date: 2024/3/30 15:32
 * @Version: 1.0
 * @name 方法名字：
 */
@RestController
public class UserController {
    @Autowired
    UserService userService;
    @Autowired
    MovieServiceFeign movieServiceFeign;

    @Value("${server.port}")
    int port;

    @RequestMapping("/getUserById/{id}")
    public User getUserId(@PathVariable("id") Integer UserId) {
        User user = userService.getUserId(UserId);
        return user;
    }

    /**
     * @Author: zy 690748807@qq.com
     * @Param: 用户ID 电影票ID
     * @return:
     * @Date: 2024/3/30
     * @Description: 用户购买电影票
     */

    @RequestMapping("/getUserByMovie/{UserId}/{id}")
    public Map<String, Object> getUserByMovie(@PathVariable("UserId") Integer UserId, @PathVariable("id") Integer id) {
        System.out.println("===user=服务器的端口号是：========"+port+"===========");
        Map<String, Object> map = new HashMap<>();
        User user = userService.getUserId(UserId);
        map.put("user", user);
        //远程调用电影服务返回的结果

        Movie newMovie = movieServiceFeign.getNewMovie(id);
        map.put("movie",newMovie);
        return map;
    }
}
